//
//  VKMeMessageCell.m
//  V-Learn
//
//  Created by liubo on 2019/1/11.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKMeMessageCell.h"

@implementation VKMeMessageCell{
    UIImageView *_imageV;
    UILabel *_contentLabel;
    UILabel *_countLabel;
}

+ (instancetype)cellWithTableView:(UITableView *)tableView{
    VKMeMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"VKMeMessageCell"];
    if (cell == nil) {
        cell = [[VKMeMessageCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"VKMeMessageCell"];
    }
    tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    return cell;
}
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // 点击cell的时候不要变色
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        
        // 布局子控件
        [self autoLayout];
    }
    return self;
}

-(void)setModel:(VKMeMessageModel *)model{
    _model = model;
    _contentLabel.text = model.content;
    _imageV.image = [UIImage imageNamed:model.imageString];
    if (model.isSelect == NO) {
        if ([model.sys integerValue] == 0) {
            _countLabel.hidden = YES;
        }else{
            _countLabel.text = [NSString stringWithFormat:@"   %@   ",model.sys];
            _countLabel.hidden = YES;
        }
    }else if (model.isSelect == YES){
        if ([model.plat integerValue] == 0) {
            _countLabel.hidden = YES;
        }else{
            _countLabel.text = [NSString stringWithFormat:@"   %@   ",model.plat];
            _countLabel.hidden = YES;
        }
    }
}

- (void)autoLayout{
    
    UIImageView *imageV = [[UIImageView alloc]init];
    _imageV = imageV;
    [self.contentView addSubview:imageV];
    [imageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.width.mas_equalTo(30);
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    UILabel *contentLabel = [[UILabel alloc]init];
    _contentLabel = contentLabel;
    [self.contentView addSubview:contentLabel];
    contentLabel.textColor = [UIColor cz_colorWithRed:62 green:62 blue:62];
    contentLabel.font = [UIFont systemFontOfSize:17];
    [contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(imageV.mas_right).offset(10);
        make.centerY.mas_equalTo(imageV);
    }];
    
    UIImageView *arrowImageV = [[UIImageView alloc]init];
    arrowImageV.image = [UIImage imageNamed:@"left"];
    [self.contentView addSubview:arrowImageV];
    [arrowImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    UILabel *countLabel = [[UILabel alloc]init];
    _countLabel = countLabel;
    [self.contentView addSubview:countLabel];
    countLabel.textColor = [UIColor whiteColor];
    countLabel.backgroundColor = [UIColor redColor];
    countLabel.layer.cornerRadius = 10;
    countLabel.layer.masksToBounds = YES;
    countLabel.font = [UIFont systemFontOfSize:13];
    [countLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(arrowImageV).offset(-20);
        make.centerY.mas_equalTo(imageV);
        make.height.equalTo(@20);
    }];
}

@end
